package nextoffer.Tencent2;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {


    public ListNode solve (ListNode[] a) {
        // write code here
        for(int i =0 ;i < a.length;i++){
            a[i] = sort(a[i]);
        }
        return mergeSort(a,0, a.length - 1);
    }

    public ListNode sort(ListNode a){
        ArrayList<Integer> b = new ArrayList<>();
        while(a != null){
            b.add(a.val);
            a = a.next;
        }
        Collections.sort(b);
        ListNode c = new ListNode(-1);
        ListNode res = c;
        for (int i = 0; i < b.size(); i++) {
            ListNode t = new ListNode(b.get(i));
            c.next = t;
            c = c.next;

        }
        c.next = null;
        return res.next;
    }
    public ListNode mergeSort(ListNode[] a, int left ,int right){
        if(left > right) return  null;
        if(left == right) return a[left];
        int l = left, r = right;
        int mid = (l + r) >> 1;
        return  merge(  mergeSort(a, l, mid),   mergeSort(a, mid + 1, r));
    }
    public ListNode merge(ListNode a ,ListNode b){
        ListNode res = new ListNode(-1);
        ListNode re = res;
        while(a != null && b!=null) {
            if(a.val < b.val) {
                res.next = a;
                a = a.next;
            } else {
                res.next = b;
                b = b.next;
            }
            res = res.next;
        }
        res.next = a == null ? b : a;
        return re.next;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) {// 注意，如果输入是多个测试用例，请通过while循环处理多个测试用例
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(a + b);
        }
    }
}
  class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}